<template>
  <div class="content_box">
    <div class="main-box">
      <p class="main-title">完善当事人信息</p>
      <p class="main-text">注：当事人信息一旦修改不可修改，日期请与文书一致后续可案件延期申请。</p>
      <el-form :model="form" :rules="rules" ref="updateForms">
        <el-form-item label="当事人姓名" label-width="110px" prop="crime_name">
          <el-input
            style="width:90%"
            size="large"
            v-model="form.crime_name"
            type="text"
            placeholder="请输入当事人姓名"
          />
        </el-form-item>

        <el-form-item label="性别" label-width="110px" prop="crime_sex">
          <el-radio-group v-model="form.crime_sex">
            <el-radio label="male">男</el-radio>
            <el-radio label="female">女</el-radio>
          </el-radio-group>
        </el-form-item>
        
        <el-form-item label="手机号" label-width="110px" prop="crime_mobile">
          <el-input
            style="width:90%"
            size="large"
            v-model="form.crime_mobile"
            type="text"
            placeholder="请输入手机号"
          />
        </el-form-item>

        <el-form-item label="身份证号码" label-width="110px" prop="crime_idcard">
          <el-input
            style="width:90%"
            size="large"
            v-model="form.crime_idcard"
            type="text"
            placeholder="请输入身份证号码"
          />
        </el-form-item>

        <el-form-item
          label="出生日期"
          label-width="110px"
          prop="crime_date"
        >
          <el-date-picker
            style="width:90%"
            size="large"
            v-model="form.crime_date"
            type="datetime"
            placeholder="请选择出生日期"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item label="家庭地址" label-width="110px" prop="crime_address">
          <el-input
            style="width:90%"
            size="large"
            v-model="form.crime_address"
            type="text"
            placeholder="请输入家庭地址"
          />
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button
          :loading="loading"
          :disabled="loading"
          type="primary"
          @click="submit"
        >
          提交
        </el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref, computed } from "vue";
import { ElNotification } from "element-plus";
import { saveCrimeInfo } from "@/api/bond/pay";

const props = defineProps({
  bailId: {
    type: Number,
  },
  id: {
    type: Number,
  },
});

let form = ref({
  bail_id: props.id,
  crime_name: '',
  crime_sex: '',
  crime_idcard:'',
  crime_date:'',
  crime_address:'',
  crime_mobile:''
});

const emit = defineEmits(['closeDrawer']);

/*=====提交=====*/
const updateForms = ref();
let loading = ref(false);
const rules = reactive({
  crime_name: [
    { required: true, message: "请输入当事人姓名", trigger: "blur" },
  ],
  crime_sex: [
    { required: true, message: "请选择性别", trigger: "change" },
  ],
  crime_idcard: [
    { required: true, message: "请输入身份证号码", trigger: "blur" },
  ],
  crime_date: [
    { required: true, message: "请选择出生日期", trigger: "change" },
  ],
  crime_address: [
    { required: true, message: "请输入家庭地址", trigger: "blur" },
  ],
  crime_mobile: [
    { required: true, message: "请输入手机号", trigger: "blur" },
  ],
});

const submit = async () => {
  console.log(form.value);
  await updateForms.value.validate();
  loading.value = true;
  await saveCrimeInfo(form.value).then((res) => {
    if (res.code == 1) {
      ElNotification({ message: res.msg, type: "success" });
      close()
    } else {
      loading.value = false;
      ElNotification.error(res.msg);
    }
  });
};

// 关闭
const close=()=>{
  form.value.crime_name = ''
  form.value.crime_sex = ''
  form.value.crime_idcard = ''
  form.value.crime_date = ''
  form.value.crime_address = ''
  form.value.crime_mobile = ''
  loading.value = false
  setTimeout(() => {
    updateForms.value.clearValidate();
  }, 500);
  
  emit("closeDrawer");
}
</script>
<style scoped lang="scss">
.dialog-footer {
  margin-top:50px;
  text-align: center;
}
.main-box{
  min-height: auto;
}
.main-text{
  margin:20px 0 47px 0;
  font-size: 14px;
  color: #323C4F;
}
</style>
  